package com.app.fk.mensa;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class MyUtilities {

	public static int getWeekFromDate() {
    	Date date = new Date();
                    
    	Calendar toolCalendar = Calendar.getInstance();

    	toolCalendar.clear();
    	toolCalendar.setTime( date );
    	return toolCalendar.get( Calendar.WEEK_OF_YEAR );
    }
	
	public static String getDateFromWeek(int week){
		final CalendarWeek calendarWeek = new CalendarWeek(week,Locale.GERMANY);
		
		
		return calendarWeek.getStart().getDate()+
				"."+ 
				calendarWeek.getStartMonth() + 
				"."+
				calendarWeek.getStartYear() + 
				" - " + 
				calendarWeek.getEnd().getDate()+
				"."+
				calendarWeek.getEndMonth() +
				"."+
				calendarWeek.getEndYear()		
				;
		
	}
	
	 static class CalendarWeek {
	        int weekOfYear;
	 
	        Date start;
	 
	        Date end;
	        
	        int start_jahr;
	        int end_jahr;
	        
	        int start_month;
	        int end_month;
	 
	        public CalendarWeek(final int weekOfYear,final Locale locale) {
	            this.weekOfYear = weekOfYear;
	 
	            final GregorianCalendar calendar = new GregorianCalendar(locale);
	            final int CURRENT_YEAR = calendar.get(Calendar.YEAR);
	            calendar.clear();
	            calendar.set(Calendar.YEAR,CURRENT_YEAR);
	            calendar.set(Calendar.WEEK_OF_YEAR, this.weekOfYear);
	            
	            this.start = calendar.getTime();
	            this.start_jahr = this.start.getYear()+1900;
	            this.start_month = this.start.getMonth()+1;
	            calendar.add(Calendar.DAY_OF_MONTH, 6);
	            
	            this.end = calendar.getTime();
	            this.end_jahr = this.end.getYear()+1900;
	            this.end_month = this.end.getMonth()+1;

	        }
	        
	        public int getStartYear() {
	        	return start_jahr;
	        }
	        public int getEndYear() {
	        	return end_jahr;
	        }
	        public Date getEnd() {
	            return end;
	        }
	        
	        public int getEndMonth() {
	            return end_month;
	        }
	        public int getStartMonth() {
	            return start_month;
	        }
	 
	        public Date getStart() {
	            return start;
	        }
	 
	        public int getWeekOfYear() {
	            return weekOfYear;
	        }
	    }
	

}
